package com.hbny.dynamicDataSource.service.impl;

import com.hbny.dynamicDataSource.DO.TenantDataBaseConfigDO;
import com.hbny.dynamicDataSource.exception.ApplicationException;
import com.hbny.dynamicDataSource.mapper.TenantInfoMapper;
import com.hbny.dynamicDataSource.service.TenantInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : Aaron
 * @date : 2022/6/2
 */
@Service
public class TenantInfoServiceImpl implements TenantInfoService {

    @Autowired
    private TenantInfoMapper mapper;

    @Override
    public List<TenantDataBaseConfigDO> getBaseInfoList() {
        return mapper.selectAllList();
    }

    @Override
    public TenantDataBaseConfigDO getTenantInfoById(String id) {
        if (StringUtils.isBlank(id)) {
            throw new ApplicationException("租户ID不能为空！");
        }
        TenantDataBaseConfigDO tenantInfo = mapper.selectTenantInfoById(id);
        if (tenantInfo == null) {
            throw new ApplicationException(5004, "当前租户不存在！");
        }
        return tenantInfo;
    }
}
